Skip to content

Conversation

@rimrul
Copy link
Member

@rimrul rimrul commented Jan 5, 2025

CreateFileW() requires FILE_FLAG_BACKUP_SEMANTICS to create a directory handle and errors out with ERROR_ACCESS_DENIED without this flag. Fall back to accessing Directory handles this way.

This fixes #5068

CreateFileW() requires FILE_FLAG_BACKUP_SEMANTICS to create a directory
handle [1] and errors out with ERROR_ACCESS_DENIED without this flag.
Fall back to accessing Directory handles this way.

[1] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories

This fixes git-for-windows#5068

Signed-off-by: Matthias Aßhauer <[email protected]>
if (handle == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
if (err == ERROR_ACCESS_DENIED) {
DWORD attrs = GetFileAttributesW(filename);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably also check GetFileAttributesW() before the first CreateFileW() and avoid calling CreateFileW() twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current version is fine because it optimizes for the common case, avoiding the extra GetFileAttributesW() & CreateFileW() calls for the vast majority of calls.

if (handle == INVALID_HANDLE_VALUE) {
DWORD err = GetLastError();
if (err == ERROR_ACCESS_DENIED) {
DWORD attrs = GetFileAttributesW(filename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current version is fine because it optimizes for the common case, avoiding the extra GetFileAttributesW() & CreateFileW() calls for the vast majority of calls.

@dscho
Copy link
Member

dscho commented Jan 7, 2025

It looks like t5616 has a newly-introduced flake now:

  ++ git -c protocol.version=0 -c gc.autoPackLimit=0 -c maintenance.incremental-repack.auto=1234 -C pc1 fetch --refetch origin
 error: unable to open .git/objects/pack/pack-6ac94f9c26c537ad200c52c992a627f57871f8aa.pack: No such file or directory
 fatal: unable to rename temporary '*.pack' file to '.git/objects/pack/pack-6ac94f9c26c537ad200c52c992a627f57871f8aa.pack'
 fatal: index-pack failed

I've restarted the job.

Copy link
Member

@dscho dscho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@dscho dscho merged commit f045ed3 into git-for-windows:main Jan 23, 2025
49 checks passed
@dscho
Copy link
Member

dscho commented Jan 23, 2025

/add relnote bug Git for Windows used to issue a misleading warning when .gitignore was a directory, which has been fixed.

The workflow run was started

@dscho dscho added this to the Next release milestone Jan 23, 2025
github-actions bot pushed a commit to git-for-windows/build-extra that referenced this pull request Jan 23, 2025
Git for Windows used [to issue a misleading warning when `.gitignore`
was a directory](git-for-windows/git#5068),
which has been
[fixed](git-for-windows/git#5342).

Signed-off-by: gitforwindowshelper[bot] <[email protected]>
dscho added a commit that referenced this pull request Jan 27, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Jan 27, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Jan 27, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Jan 27, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jan 27, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jan 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jan 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 5, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 5, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 5, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Feb 5, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 6, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 6, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Feb 6, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit to dscho/git that referenced this pull request Feb 6, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes git-for-windows#5068
dscho added a commit to dscho/git that referenced this pull request Feb 6, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes git-for-windows#5068
git-for-windows-ci pushed a commit that referenced this pull request Feb 13, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Feb 13, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 17, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Jul 19, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 21, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 21, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 22, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 22, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Jul 23, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 23, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 23, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 24, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 24, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 24, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Jul 25, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 25, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 25, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Aug 1, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Aug 1, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Aug 1, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Aug 1, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Aug 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
dscho added a commit that referenced this pull request Aug 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Aug 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Aug 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Aug 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
git-for-windows-ci pushed a commit that referenced this pull request Aug 3, 2025
[`CreateFileW()` requires `FILE_FLAG_BACKUP_SEMANTICS` to create a
directory
handle](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories)
and errors out with `ERROR_ACCESS_DENIED` without this flag. Fall back
to accessing Directory handles this way.

This fixes #5068
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading warning when a directory is named .gitignore

2 participants